package day04

// day04
//
// 674. 最长连续递增序列
//
// https://leetcode.cn/problems/longest-continuous-increasing-subsequence/
//
// ```go
func findLengthOfLCIS(nums []int) int {
	n := len(nums)
	dp := make([]int, n)
	for i := range dp {
		dp[i] = 1
	}
	ans := 1
	for i := 1; i < n; i++ {
		if nums[i] > nums[i-1] {
			dp[i] = dp[i-1] + 1
		}
		ans = max(ans, dp[i])
	}
	return ans
}

//```

// 718. 最长重复子数组
//
// https://leetcode.cn/problems/maximum-length-of-repeated-subarray/
//
// ```go
func findLength(nums1 []int, nums2 []int) int {
	n, m := len(nums1), len(nums2)
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m+1)
	}
	ans := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if nums1[i-1] == nums2[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			}
			ans = max(ans, dp[i][j])
		}
	}
	return ans
}

//```

// 1143. 最长公共子序列
//
// https://leetcode.cn/problems/longest-common-subsequence/
//
// ```go
func longestCommonSubsequence(text1 string, text2 string) int {
	n, m := len(text1), len(text2)
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, m+1)
	}
	ans := 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if text1[i-1] == text2[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1])
			}
			ans = max(ans, dp[i][j])
		}
	}
	return ans
}

//```
